package com.hand.wfive.loginAndVip.ui

import android.app.Dialog
import android.content.Context
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView
import com.hand.wfive.R
import com.hand.wfive.activity.PrivacyActivity
import com.hand.wfive.loginAndVip.model.ActivityCouponModel
import com.hand.wfive.util.click.singleClick
import com.hand.wfive.view.countdowntime.CountDownTimerView
import org.jetbrains.anko.find
import org.jetbrains.anko.findOptional

/**
 * VIP购买支付时为选中同意购买协议时弹出
 * 取消->关闭
 * 继续购买->同意购买协议后继续支付
 */
class BuyKnowDialog(context: Context, event: () -> Unit) : Dialog(context, R.style.CustomDialog) {
    init {
        setContentView(R.layout.login_dialog_buy_know)
        find<QMUIAlphaTextView>(R.id.qtv_agreement).singleClick {
            PrivacyActivity.showRule(getContext(), PrivacyActivity.VIPRULE)
        }
        find<QMUIAlphaTextView>(R.id.qtv_cancel).singleClick { dismiss() }
        find<QMUIAlphaTextView>(R.id.qtv_sure).singleClick {
            dismiss()
            event()
        }
    }
}

/**
 * VIP返回
 */
class VipBackDialog(context: Context, event: () -> Unit) : Dialog(context, R.style.CustomDialog) {
    init {
        setContentView(R.layout.login_dialog_vip_back)
        // 立即购买
        find<ImageView>(R.id.purchase).singleClick { dismiss() }
        // 残忍离开
        find<TextView>(R.id.leave).singleClick {
            dismiss()
            event()
        }
    }
}

/**
 * VIP返回有优惠券或者优惠券已过期的时弹出
 */
//class VipBackCouponDialog(
//    context: Context, time: Long,
//    data: MutableList<ActivityCouponModel>,
//    event: (Int) -> Unit
//) : Dialog(context, R.style.CustomDialog) {
//    init {
//        setContentView(R.layout.login_dialog_vip_back_coupon)
//        val countdownView = find<CountDownTimerView>(R.id.couponCountdownView)
//        countdownView.cancelDownTimer()
//        countdownView.setDownTime(time)
//        countdownView.setDownTimerLastListener {
//            dismiss()
//            event(1)
//        }
//        countdownView.startDownTimer()
//
//        val recyclerView = find<RecyclerView>(R.id.recycler_coupon)
//        recyclerView.layoutManager = LinearLayoutManager(context)
//        recyclerView.adapter = VipBackCounpAdapter(data)
//        find<TextView>(R.id.tv_receive).singleClick {
//            dismiss()
//            event(0)
//        }
//        find<TextView>(R.id.tv_leave).singleClick {
//            dismiss()
//            event(1)
//        }
//        window?.setLayout(
//            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT
//        )
//    }
//
//    override fun dismiss() {
//        findOptional<CountdownView>(R.id.couponCountdownView)?.cancelDownTimer()
//        super.dismiss()
//    }

//}